package com.mars.admin.modules.activity.service.impl;

import com.mars.admin.modules.activity.entity.ActivityCategory;
import com.mars.admin.modules.activity.mapper.ActivityCategoryMapper;
import com.mars.admin.modules.activity.service.ActivityCategoryService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.mars.admin.modules.activity.entity.table.ActivityCategoryTableDef.ACTIVITY_CATEGORY;

/**
 * 活动分类服务实现类
 *
 * @author Mars
 * @version 1.0
 * @date 2025-01-07
 */
@Service
public class ActivityCategoryServiceImpl extends ServiceImpl<ActivityCategoryMapper, ActivityCategory> implements ActivityCategoryService {

    @Override
    public List<ActivityCategory> getCategoryTree() {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(ACTIVITY_CATEGORY.STATUS.eq(1))
                .orderBy(ACTIVITY_CATEGORY.SORT_ORDER.asc(), ACTIVITY_CATEGORY.ID.asc());
        return list(queryWrapper);
    }

    @Override
    public List<ActivityCategory> getChildrenByParentId(Long parentId) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(ACTIVITY_CATEGORY.PARENT_ID.eq(parentId))
                .and(ACTIVITY_CATEGORY.STATUS.eq(1))
                .orderBy(ACTIVITY_CATEGORY.SORT_ORDER.asc(), ACTIVITY_CATEGORY.ID.asc());
        return list(queryWrapper);
    }

    @Override
    public List<ActivityCategory> getHotCategories(Integer limit) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(ACTIVITY_CATEGORY.STATUS.eq(1))
                .and(ACTIVITY_CATEGORY.IS_HOT.eq(1))
                .orderBy(ACTIVITY_CATEGORY.SORT_ORDER.asc(), ACTIVITY_CATEGORY.ID.asc())
                .limit(limit);
        return list(queryWrapper);
    }

    @Override
    public List<ActivityCategory> getEnabledCategories() {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(ACTIVITY_CATEGORY.STATUS.eq(1))
                .orderBy(ACTIVITY_CATEGORY.SORT_ORDER.asc(), ACTIVITY_CATEGORY.ID.asc());
        return list(queryWrapper);
    }
} 